package zozopo.background.operator;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.json.JSONObject;

import zozopo.attendance.operations.OperatorAttendanceOS;
import zozopo.attendance.operations.OperatorAttendanceTB;
import zozopo.background.operator.operations.OperatorTB;
import zozopo.warehouse.operations.ReceiptlistOS;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class InfoAction extends ActionSupport implements Action ,SessionAware, ServletRequestAware{
	
	//输出参数
	private String reportJSONStr;
	private String reportDate;
	private String reportNum;
	private String reportTotal;
	
	private OperatorAttendanceTB operatorofattendance;
	
	private HttpServletRequest request;
	private Map<Object, Object> session;
	
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}
	
	
	
	
	public String execute() throws Exception {
		//ActionContext actionContext = ActionContext.getContext(); 

		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return NONE; 
		} 
		
		ReceiptlistOS receiptlistOS = new ReceiptlistOS();
		OperatorAttendanceOS operatorOfAttendanceOS = new OperatorAttendanceOS(receiptlistOS.getConn());
		
		if(operatorOfAttendanceOS.isExistOperatorid(operator.getId_operator())){
			//考勤信息
			operatorofattendance = operatorOfAttendanceOS.getInfoByOperatorid(operator.getId_operator());
			
			reportJSONStr = receiptlistOS.getDateCountNum(-12);
			JSONObject jsonObj = new JSONObject(reportJSONStr);
			reportDate = jsonObj.get("date").toString();
			reportNum = jsonObj.get("num").toString();
			reportTotal = jsonObj.get("total").toString();
		}
		
		receiptlistOS.releaseConnection();
		
		return SUCCESS;
	}

	public String getReportJSONStr() {
		return reportJSONStr;
	}

	public void setReportJSONStr(String reportJSONStr) {
		this.reportJSONStr = reportJSONStr;
	}

	public String getReportDate() {
		return reportDate;
	}

	public void setReportDate(String reportDate) {
		this.reportDate = reportDate;
	}

	public String getReportNum() {
		return reportNum;
	}

	public void setReportNum(String reportNum) {
		this.reportNum = reportNum;
	}

	public String getReportTotal() {
		return reportTotal;
	}

	public void setReportTotal(String reportTotal) {
		this.reportTotal = reportTotal;
	}

	public OperatorAttendanceTB getOperatorofattendance() {
		return operatorofattendance;
	}

	public void setOperatorofattendance(OperatorAttendanceTB operatorofattendance) {
		this.operatorofattendance = operatorofattendance;
	}

}
